/* The code examples copyrighted by Nokia Corporation that are included to
 * this material are licensed to you under following MIT-style License:
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the
 * "Software"), to deal in the Software without restriction, including
 * without limitation the rights to use, copy, modify, merge, publish,
 * distribute, sublicense, and/or sell copies of the Software, and to
 * permit persons to whom the Software is furnished to do so, subject to
 * the following conditions:
 *
 * The above copyright notice and this permission notice shall be included
 * in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */

import Qt 4.7
import com.meego 1.0

Page {
    id: page
    property int fontSize: 18
    anchors.margins: 10
    tools: commonTools

    QueryDialog {
        id: errorDialog
        titleText: "Error"
        message: "Please enter Caption and User name."
        acceptButtonText: "Ok"
    }
    Flickable {
        id: container
        anchors.fill: parent
        flickableDirection: Flickable.VerticalFlick
        pressDelay: 100

        Column {
            spacing: 5
            width: parent.width

            Text {text: "<b>Create Identity: </b>"; font.pointSize: fontSize}
            Grid {
                columns: 2
                Text { text: "Caption: "; width:  username.width; font.pointSize: fontSize }
                TextField { id: identityCaption }

                Text { id: username; text: "User name: "; font.pointSize: fontSize}
                TextField { id: identityUserName }

                Text { text: "Password: "; width:  username.width; font.pointSize: fontSize }
                TextField { id: identityPassword; echoMode: TextInput.Password }
            }

            Text {text: "<b>New Identity methods: </b>"; font.pointSize: fontSize}

            ListView {
                id: methodsIdView
                width: page.width / 2
                height: (page.width > page.height) ? page.height / 5 :  page.height / 2
                model: MethodsAvailable
                clip: true
                delegate: Text { text: modelData; font.pointSize: fontSize; width: parent.width
                    MouseArea {
                        anchors.fill: parent
                        onClicked: { methodsIdView.currentIndex = index }
                    }
                }

                highlight: Rectangle { color: "lightsteelblue"; radius: 5 }
                highlightFollowsCurrentItem: true
            }

            Button {
                text: "Store Identity"
                onClicked: {
                    if (identityCaption.text == "" || identityUserName.text == "") {
                        errorDialog.open()
                    } else {
                        SignonExample.createIdentity(identityCaption.text, identityUserName.text, identityPassword.text, methodsIdView.currentItem.text)
                        pageStack.pop()
                    }

                }
            }
        }
    }
}
